import 'package:flutter/material.dart';
import 'package:flutter_demo/core/common/utils/image_utils.dart';
import 'package:flutter_demo/core/common/values/gaps.dart';
import 'package:flutter_demo/ui/pages/search/view.dart';
import 'package:flutter_demo/ui/pages/treasure/controller.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class SearchAppbar extends StatelessWidget implements PreferredSizeWidget {
  final controller = GetInstance().find<TreasureController>();
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Get.toNamed(SearchPage.routeName, arguments: {
          "keywords": controller.defuleSearch.value,
          'channel': '1'
        });
        //logger.i("--搜索-");
      },
      child: Container(
          //作用于内部组件
          padding: EdgeInsets.only(left: 18.w, right: 18.w),
          //margin: EdgeInsets.only(right: 15.w, left: 56.w),
          width: 300.w,
          height: 50.h,
          //圆角颜色，背景
          decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(25.r)),
              color: Get.isDarkMode ? Colors.white12 : Colors.blueGrey),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Image.asset(
                ImageUtils.getImagePath('search'),
                color: Colors.white,
                width: 15.w,
                height: 15.h,
              ),
              Gaps.hGap8,
              Obx(() => SizedBox(
                  width: 210.w,
                  child: Text(
                    controller.defuleSearch.value.isEmpty
                        ? "搜索"
                        : controller.defuleSearch.value,
                    softWrap: false,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ))),
            ],
          )),
    );
  }

  @override
  Size get preferredSize =>
      Size.fromHeight(Get.theme.appBarTheme.toolbarHeight!);
}
